<?php
class db{
    var $link;
    var $result;
		
	public function db($args){
		global $core;
		$this->link = mysql_connect($args['server'], $args['user'], $args['pass']) or die($core->mui['no_db_connect']);
        mysql_select_db($args['name'], $this->link);
		mysql_query("SET NAMES utf8", $this->link);
        return $this->link;
	}

    public function sql_close(){
        if($this->link){
            mysql_close($this->link);
        }
    }

    public function sql_query($qstring){
        if($this->link && $qstring != ''){
            $this->result = mysql_query($qstring,  $this->link);
            return $this->result;
        }
    }

    public function sql_fetchrow($qid = 0){
        if($qid == 0) $qid = $this->result;
        if($this->result) return mysql_fetch_array($qid);
    }

    public function sql_nextid(){
        if($this->link) return mysql_insert_id($this->link);
		else return false;
    }

    public function sql_numrows($qid = 0){
        if($qid == 0) $qid = $this->result;
        if($this->result) return mysql_num_rows($qid);
    }
    
    public function sql_affectedrows($qid = 0){
        if($this->link) return mysql_affected_rows($this->link);
        else return false;
    }

    public function sql_error($qid = 0){
        if($qid == 0) $qid = $this->link;
        if($this->link) return mysql_error($qid);
    }
}
?>
